package com.dnjn.mes.common.utils;

public class CountModbusAddrUtil {

    //获取基础信息modbus地址
    public static Integer getRegisterModbusAddrByPlcAddr(String addrPlc) {
        Integer modbus = 0;
        String split = "";
        if (addrPlc.contains(".")){
            split = addrPlc.split("\\.")[0].substring(2);
        }else {
            split = addrPlc.substring(2);
        }
        int parseInt = Integer.parseInt(split);
        modbus = parseInt/2;//QW开头（正常）: n/2+1（读取不到数据） -> n/2(能读取到数据)
        return modbus;
    }

    //获取except得modbus地址
    public static Integer getExceptModbusAddrByPlcAddr(String addrPlc) {
        Integer modbus = 0;
        String split = "";
        if (addrPlc.contains(".")){
            split = addrPlc.split("\\.")[0].substring(2);
        }else {
            split = addrPlc.substring(2);
        }
        int parseInt = Integer.parseInt(split);
        modbus = parseInt/2+12288;//MX开头（异常） n/2+12288
        return modbus;
    }

}
